﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using NPSoft.Ferrero.DataBridge.Model;
using NPSoft.Ferrero.Framework.DAL;

namespace NPSoft.Ferrero.DataBridge.DAL
{
    public class ProductCTPriceUtil : IDAL<ProductCTPrice>
    {
        public int Add(ProductCTPrice info)
        {
            throw new NotImplementedException();
        }

        public int Edit(ProductCTPrice info)
        {
            throw new NotImplementedException();
        }

        public ProductCTPrice GetById(long id)
        {
            throw new NotImplementedException();
        }

        public ProductCTPrice GetById(Guid id)
        {
            throw new NotImplementedException();
        }

        public int Remove(ProductCTPrice info)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataSet Search(StringBuilder condtion)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// SQL连接
        /// </summary>
        private SqlConnection Connection
        {
            get
            {
                return SqlHelper.GetConnection();
            }
        }

        public ICollection<ProductCTPrice> SearchCollection(StringBuilder condtion)
        {
            ICollection<ProductCTPrice> infos = new List<ProductCTPrice>();
            StringBuilder sql = new StringBuilder();
            sql.Append(@"SELECT PRD_CD,UOM,COST_PRC,START_TIME,END_TIME,CURRENCY,TYPE,COND_PRICE_UNIT FROM	MST_PRDCOSTPRICE ");

            string sWhere = " where ";
            if (!string.IsNullOrEmpty(condtion.ToString()))
            {

                sql.Append(sWhere + condtion);
            }
            DataSet ds;
            ds = SqlHelper.ExecuteDataset(this.Connection, CommandType.Text, sql.ToString());
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                infos.Add(SetInfo(row));
            }
            return infos;
        }

        public ProductCTPrice SetInfo(System.Data.DataRow row)
        {
            ProductCTPrice proCTPrice = new ProductCTPrice();
            proCTPrice.PRD_CD = SqlHelper.GetString(row, "PRD_CD");
            proCTPrice.UOM = SqlHelper.GetString(row, "UOM");
            proCTPrice.RATE = SqlHelper.GetString(row, "COST_PRC");
            proCTPrice.RATE_UNIT = SqlHelper.GetString(row, "CURRENCY");
            proCTPrice.START_TIME = SqlHelper.GetString(row, "START_TIME");
            proCTPrice.END_TIME = SqlHelper.GetString(row, "END_TIME");
            proCTPrice.TYPE = SqlHelper.GetString(row, "TYPE");
            proCTPrice.PRI_UNIT = SqlHelper.GetString(row, "COND_PRICE_UNIT");


            return proCTPrice;
        }
    }
}
